home *** CD-ROM | disk | FTP | other *** search
/ Just Call Me Internet / Just Call Me Internet.iso / prog / atari / c / stngpasm / pure_c / include / uran / uran_xb.sh < prev   
Encoding:
Text File  |  1997-08-18  |  9.1 KB  |  335 lines

  1. ;----------------------------------------------------------------------------
  2. ;File name:    URAn_XB.SH            Revision date:    1997.08.19
  3. ;Creator:    Ulf Ronald Andersson        Creation date:    1991.05.07
  4. ;(c)1991 by:    Ulf Ronald Andersson        All rights reserved
  5. ;Released as:    FREEWARE            (commercial sale forbidden)
  6. ;----------------------------------------------------------------------------
  7. ;Purpose:    Macro library for XBRA operations
  8. ;----------------------------------------------------------------------------
  9. ;Required header declarations:
  10. ;
  11. ;    include    "uran\STRUCT.SH"
  12. ;    include    "uran\URAn_SYS.SH"
  13. ;    include    "uran\URAn_DOS.SH"
  14. ;    include    "uran\URAn_XB.SH"
  15. ;
  16. ;----------------------------------------------------------------------------
  17. ;    Library macros:
  18. ;
  19. ;   The first 4 alter no registers
  20. ; XB_define    xbname,xbra_id    Defines header for routine code
  21. ; XB_gonext    xbname        Smart Link to next routine in chain
  22. ; XB_gonext_d    xbname        FAST Link to next routine in chain
  23. ; XB_donext_d    xbname        FAST Call to next routine in chain
  24. ;
  25. ;   The next 2 alter only register a0
  26. ; XB_gonext_a0    xbname        BEST Link to next routine in chain
  27. ; XB_donext_a0    xbname        BEST Call to next routine in chain
  28. ;
  29. ;   The next 2 alter only the choosen "areg"
  30. ; Pass_Frame    areg            areg->exception argument
  31. ; XB_donext    xbname,areg        Smart Call to next routine in chain
  32. ;
  33. ;   The next 3 affect d0-d2/a0-a2, since they use XBIOS Supexec
  34. ; XB_check    xbname,root        d0= found/last vector  flagged PL/MI
  35. ; XB_install    xbname,root        " + Installs xbname in chain(root)
  36. ; XB_remove    xbname,root        " + Removes xbname from chain(root)
  37. ;
  38. ; Legal forms for xbname & root here are mostly the same as for LEA & PEA,
  39. ;   except that for XB_define "xbname" is a free name for the new structure.
  40. ; "xbname" always refers to the first byte of the entire structure.
  41. ; "xbra_id" is a 4-character (longword) string
  42. ; "areg" is a free address register of your choice.
  43. ; XB_gonext_d & XB_donext_d are faster versions of XB_gonext & XB_donext,
  44. ;   but can only handle address modes where "xbname" begins with identifier.
  45. ;   eg: "XB_donext_d  my_ikbd_sub(pc)"  but  "XB_donext  (a5)+")
  46. ; XB_gonext_a0 & XB_donext_a0 are even faster, but destroy value in a0.
  47. ; Pass_Frame makes exception routines (eg: gemdos etc.) 68030-compatible,
  48. ;   by setting "areg" = stack pointer before exception (SSP or USP)
  49. ;
  50. ;XB_define may (optionally) have a third argument which, if present, will be
  51. ;placed in the link pointer as its initial value.
  52. ;
  53. ;----------------------------------------------------------------------------
  54. ;
  55.     struct    xb_struct
  56.     d_l    xb_magic
  57.     d_l    xb_id
  58.     d_l    xb_next
  59.     d_alias    xb_code
  60.     d_alias    xb_size
  61.     d_end    xb_struct
  62. ;
  63. ;----------------------------------------------------------------------------
  64. ;    Macro definitions (with support variables)
  65. ;
  66. .MACRO    Pass_Frame    areg
  67.     local    .user,.new_cpu,.have_arg
  68.     btst    #5,(sp)
  69.     beq.s    .user
  70.     tst    (_longframe).w
  71.     bne.s    .new_cpu
  72.     lea    6(sp),areg
  73.     bra.s    .have_arg
  74. .new_cpu:
  75.     lea    8(sp),areg
  76.     bra.s    .have_arg
  77. .user:
  78.     move.l    USP,areg
  79. .have_arg:
  80. .ENDM
  81. ;
  82. ;----------------------------------------------------------------------------
  83. ;
  84. .MACRO    XB_define xbname,xbra_id,init_link
  85. xbname:    dc.l    'XBRA',xbra_id
  86.     ifb    init_link
  87.     dc.l    0
  88.     else
  89.     dc.l    init_link
  90.     endif
  91. .ENDM
  92. ;
  93. ;----------------------------------------------------------------------------
  94. ;
  95. .MACRO    XB_donext_a0    xbname
  96.     move.l    8+xbname,a0
  97.     jsr    (a0)
  98. .ENDM
  99. ;
  100. ;
  101. .MACRO    XB_donext_d    xbname
  102.     local    .retadr
  103.     pea    .retadr(pc)
  104.     move.l    8+xbname,-(sp)
  105.     rts
  106. .retadr:
  107. .ENDM
  108. ;
  109. ;
  110. .MACRO    XB_donext    xbname,areg
  111.     lea    xbname,areg
  112.     move.l    8(areg),areg
  113.     jsr    (areg)
  114. .ENDM
  115. ;
  116. ;----------------------------------------------------------------------------
  117. ;
  118. .MACRO    XB_gonext_a0    xbname
  119.     move.l    8+xbname,a0
  120.     jmp    (a0)
  121.     endm
  122. ;
  123. ;
  124.     macro    XB_gonext_d    xbname
  125.     move.l    8+xbname,-(sp)
  126.     rts
  127.     endm
  128. ;
  129. ;
  130.     macro    XB_gonext    xbname
  131.     movem.l    a0-a1,-(sp)
  132.     lea    xbname,a0
  133.     move.l    8(a0),4(sp)
  134.     move.l    (sp)+,a0
  135.     rts
  136. .ENDM
  137. ;
  138. ;----------------------------------------------------------------------------
  139. ;
  140. XB_check_defined    set    0
  141. ;
  142. .MACRO    XB_check    xbname,root
  143. ;
  144.     ifne    XB_check_defined==0
  145.     bra.s    XB_check_code_end
  146. ;
  147. XB_check_code:
  148.     movem.l    a3/a4,-(sp)
  149.     movem.l    12(sp),a3/a4    ;a3 -> struct  a4 -> chain root
  150.     subq    #4,sp        ;reserve result storage on stack
  151. ;
  152.     gemdos    Super,1.w    ;User or Super mode call ?
  153.     tst.l    d0
  154.     bmi.s    .done_super_1
  155.     gemdos    Super,!
  156. .done_super_1:            ;here CPU is in supervisor state
  157.     move.l    d0,-(sp)    ;push -1 or previous SSP
  158.     move    SR,d2        ;d2 = entry interrupt mask
  159.     or    #$0700,SR    ;disable interrupts
  160. ;
  161. .search_lp:
  162.     move.l    a4,d0
  163.     bset    #31,d0            ;flag vector missing as MI
  164.     move.l    (a4),d1
  165.     beq.s    .done_search        ;exit if vector missing
  166.     move.l    d1,a4
  167.     subq    #xb_code-xb_next,a4
  168.     cmpi.l    #'XBRA',xb_magic-xb_next(a4)
  169.     bne.s    .done_search        ;exit if chain broken
  170.     move.l    xb_id-xb_next(a4),d1    ;d1 = current id
  171.     cmp.l    xb_id(a3),d1        ;d1 == sought id ?
  172.     bne.s    .search_lp        ;loop back to check remaining chain
  173.     bclr    #31,d0        ;flag vector found as PL
  174. .done_search:
  175.     move.l    d0,4(sp)    ;store search result in stack
  176. ;
  177.     move    d2,SR        ;restore entry interrupt mask
  178.     move.l    (sp)+,d0
  179.     bmi.s    .done_super_2
  180.     gemdos    Super|_ind,d0
  181. .done_super_2:            ;here CPU is back in entry state
  182. ;
  183.     move.l    (sp)+,d0    ;d0 = search result from stack
  184.     movem.l    (sp)+,a3/a4
  185.     rts    ;d0=found_vector  or  (last_chain_vector+1<<31)
  186. XB_check_code_end:
  187.     endc
  188. ;
  189.     pea    root
  190.     pea    xbname
  191.     bsr    XB_check_code
  192.     addq    #8,sp
  193. ;
  194. XB_check_defined    set    XB_check_defined+1
  195. .ENDM    ;d0=found_vector/(last_chain_vector+1<<31) flagged PL/MI
  196. ;
  197. ;----------------------------------------------------------------------------
  198. ;
  199. XB_install_defined    set    0
  200. ;
  201. .MACRO    XB_install    xbname,root
  202.     ifne    XB_install_defined=0
  203.     bra.s    XB_install_code_end
  204. ;
  205. XB_install_code:
  206.     movem.l    a3/a4,-(sp)
  207.     movem.l    12(sp),a3/a4    ;a3 -> struct  a4 -> chain root
  208.     subq    #4,sp        ;reserve result storage on stack
  209. ;
  210.     gemdos    Super,1.w    ;User or Super mode call ?
  211.     tst.l    d0
  212.     bmi.s    .done_super_1
  213.     gemdos    Super,!
  214. .done_super_1:            ;here CPU is in supervisor state
  215.     move.l    d0,-(sp)    ;push -1 or previous SSP
  216.     move    SR,d2        ;d2 = entry interrupt mask
  217.     or    #$0700,SR    ;disable interrupts
  218. ;
  219.     move.l    a3,a1
  220.     move.l    a4,a2
  221. ;
  222. .search_lp:
  223.     move.l    a4,d0
  224.     bset    #31,d0            ;flag vector missing as MI
  225.     move.l    (a4),d1
  226.     beq.s    .done_search        ;exit if vector missing
  227.     move.l    d1,a4
  228.     subq    #xb_code-xb_next,a4
  229.     cmpi.l    #'XBRA',xb_magic-xb_next(a4)
  230.     bne.s    .done_search        ;exit if chain broken
  231.     move.l    xb_id-xb_next(a4),d1    ;d1 = current id
  232.     cmp.l    xb_id(a3),d1        ;d1 == sought id ?
  233.     bne.s    .search_lp        ;loop back to check remaining chain
  234.     bclr    #31,d0        ;flag vector found as PL
  235. .done_search:
  236.     move.l    d0,4(sp)    ;store search result in stack
  237. ;
  238.     bpl.s    .done_install
  239.     lea    xb_next(a1),a1
  240.     move.l    (a2),(a1)+    ;link new XBRA to old chain
  241.     move.l    a1,(a2)        ;store -> new XBRA as chain root
  242. .done_install:
  243. ;
  244.     move    d2,SR        ;restore entry interrupt mask
  245.     move.l    (sp)+,d0
  246.     bmi.s    .done_super_2
  247.     gemdos    Super|_ind,d0
  248. .done_super_2:            ;here CPU is back in entry state
  249. ;
  250.     move.l    (sp)+,d0    ;d0 = search result from stack
  251.     movem.l    (sp)+,a3/a4
  252.     rts    ;d0=found_vector  or  (last_chain_vector+1<<31)
  253. XB_install_code_end:
  254.     endc
  255. ;
  256.     pea    root
  257.     pea    xbname
  258.     bsr    XB_install_code
  259.     addq    #8,sp
  260. ;
  261. XB_install_defined    set    XB_install_defined+1
  262. .ENDM
  263. ;
  264. ;----------------------------------------------------------------------------
  265. ;
  266. XB_remove_defined    set    0
  267. ;
  268. .MACRO    XB_remove    xbname,root
  269.     ifne    XB_remove_defined=0
  270.     bra.s    XB_remove_code_end
  271. ;
  272. XB_remove_code:
  273.     movem.l    a3/a4,-(sp)
  274.     movem.l    12(sp),a3/a4    ;a3 -> struct  a4 -> chain root
  275.     subq    #4,sp        ;reserve result storage on stack
  276. ;
  277.     gemdos    Super,1.w    ;User or Super mode call ?
  278.     tst.l    d0
  279.     bmi.s    .done_super_1
  280.     gemdos    Super,!
  281. .done_super_1:            ;here CPU is in supervisor state
  282.     move.l    d0,-(sp)    ;push -1 or previous SSP
  283.     move    SR,d2        ;d2 = entry interrupt mask
  284.     or    #$0700,SR    ;disable interrupts
  285. ;
  286.     move.l    a3,a1
  287.     move.l    a4,a2
  288. ;
  289. .search_lp:
  290.     move.l    a4,d0
  291.     bset    #31,d0            ;flag vector missing as MI
  292.     move.l    (a4),d1
  293.     beq.s    .done_search        ;exit if vector missing
  294.     move.l    d1,a4
  295.     subq    #xb_code-xb_next,a4
  296.     cmpi.l    #'XBRA',xb_magic-xb_next(a4)
  297.     bne.s    .done_search        ;exit if chain broken
  298.     move.l    xb_id-xb_next(a4),d1    ;d1 = current id
  299.     cmp.l    xb_id(a3),d1        ;d1 == sought id ?
  300.     bne.s    .search_lp        ;loop back to check remaining chain
  301.     bclr    #31,d0        ;flag vector found as PL
  302. .done_search:
  303.     move.l    d0,4(sp)    ;store search result in stack
  304. ;
  305.     bmi.s    .done_remove
  306.     move.l    d0,a0                ;a0 -> link -> found XBRA
  307.     move.l    (a0),a1                ;a1 -> xb_code of found XBRA
  308.     move.l    xb_next-xb_code(a1),(a0)    ;unlink found XBRA from chain
  309. .done_remove:
  310. ;
  311.     move    d2,SR        ;restore entry interrupt mask
  312.     move.l    (sp)+,d0
  313.     bmi.s    .done_super_2
  314.     gemdos    Super|_ind,d0
  315. .done_super_2:            ;here CPU is back in entry state
  316. ;
  317.     move.l    (sp)+,d0    ;d0 = search result from stack
  318.     movem.l    (sp)+,a3/a4
  319.     rts    ;d0=found_vector  or  (last_chain_vector+1<<31)
  320. ;
  321. XB_remove_code_end:
  322.     endc
  323. ;
  324.     pea    root
  325.     pea    xbname
  326.     bsr    XB_remove_code
  327.     addq    #8,sp
  328. ;
  329. XB_remove_defined    set    XB_remove_defined+1
  330. .ENDM
  331. ;
  332. ;----------------------------------------------------------------------------
  333. ; End of file:    URAn_XB.SH
  334. ;----------------------------------------------------------------------------
  335.